<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class User_panel extends CI_Controller {

    public $layout = DEFAULTLAYOUT;

    function __construct() {
        parent::__construct();

        if ($this->session->userdata('user_id') == NULL) {
            $this->load->helper('auth_helper');
            userNotLogged();
        }
        $this->load->language('user_panel');
        $this->load->helper('auth');
    }

    function index() {
        $data['message'] = $this->session->flashdata('message');
        $this->load->view('user_panel', $data);
    }

    function  report () {
        $post = $this->input->post();

        if(!is_null($post['form'])) {
            $report = new Report();
            $report->type = $post['type'];
            $report->report = $post['report'];
            $report->user_id = get_user_id();
            $dateTime = new DateTime();
            $report->date = (string) $dateTime->format('Y-m-d H:i:sP');
            $report->resolved = 0;
            $report->save();

            set_flashdata(lang('message_report'));
            redirect('user_panel');
        } else {
            $this->load->view('report');
        }
    }

    function change_language () {
        $post = $this->input->post();

        if(!is_null($post['form'])) {
            $user_profile = new User_profile();
            $user_profile->where('user_id', get_user_id())->get();
            $user_profile->language = $post['language'];

            $user_profile->save();

            set_flashdata(lang('message_change_language'));
            redirect('user_panel');
        } else {
            $this->load->view('change_language');
        }
    }

}

/* End of file home.php */
/* Location: ./application/modules/home/controllers/home.php */